<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>pyzy: libpyzy - The Chinese PinYin and Bopomofo conversion library.</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">pyzy
   &#160;<span id="projectnumber">0.0.8</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li class="current"><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="headertitle">
<div class="title">libpyzy - The Chinese PinYin and Bopomofo conversion library. </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Sample code</p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;PyZy/InputContext.h&gt;</span>
<span class="preprocessor">#include &lt;PyZy/Const.h&gt;</span>
<span class="preprocessor">#include &lt;PyZy/Variant.h&gt;</span>
<span class="preprocessor">#include &lt;iostream&gt;</span>

<span class="comment">// observer class to get a notification from |InputContext|.</span>
<span class="keyword">class </span>SampleObserver : <span class="keyword">public</span> PyZy::InputContext::Observer {
<span class="keyword">public</span>:
    <span class="keywordtype">void</span> commitText (<a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context, <span class="keyword">const</span> std::string &amp;commit_text) {
        std::cout &lt;&lt; <span class="stringliteral">&quot;text is commited. [&quot;</span> &lt;&lt; commit_text &lt;&lt; <span class="stringliteral">&quot;]&quot;</span> &lt;&lt; std::endl;
    }

    <span class="keywordtype">void</span> inputTextChanged (<a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context) {
        std::cout &lt;&lt; <span class="stringliteral">&quot;input text is changed. [&quot;</span> &lt;&lt; context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a53f0ab06a72d8cd20d3d569b68b245b1" title="Returns a input text.">inputText</a>() &lt;&lt; <span class="stringliteral">&quot;]&quot;</span>
                  &lt;&lt; std::endl;
    }

    <span class="keywordtype">void</span> preeditTextChanged (<a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context) {
        std::cout &lt;&lt; <span class="stringliteral">&quot;selected text is changed. [&quot;</span> &lt;&lt; context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a0dfbb78246279dda7eb7daee352c8f02" title="Returns a selected text.">selectedText</a>()
                  &lt;&lt; <span class="stringliteral">&quot;]&quot;</span> &lt;&lt; std::endl;
    }

    <span class="keywordtype">void</span> auxiliaryTextChanged (<a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context) {
        std::cout &lt;&lt; <span class="stringliteral">&quot;conversion text is changed. [&quot;</span>
                  &lt;&lt; context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#ac61f0c1076dc3b2a1202289ff0befba2" title="Returns a conversion text.">conversionText</a>() &lt;&lt; <span class="stringliteral">&quot;]&quot;</span> &lt;&lt; std::endl;
    }

    <span class="keywordtype">void</span> candidatesChanged (<a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context) {
        std::cout &lt;&lt; <span class="stringliteral">&quot;candidates are changed.&quot;</span> &lt;&lt; std::endl;

        <span class="comment">// output first 5 candidates.</span>
        <span class="keywordflow">for</span> (<span class="keywordtype">size_t</span> i = 0; i &lt; 5; ++i) {
            <a class="code" href="structPyZy_1_1Candidate.html" title="Contains a candidate data.">PyZy::Candidate</a> candidate;
            <span class="keywordflow">if</span> (!context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#abd7aa51d9cea243fe8c9a38daf4b1437" title="Gets the candidate if exists.">getCandidate</a>(i, candidate)) {
                <span class="keywordflow">break</span>;
            }
            std::cout &lt;&lt; <span class="stringliteral">&quot;  [&quot;</span> &lt;&lt; i &lt;&lt; <span class="stringliteral">&quot;]: &quot;</span> &lt;&lt; candidate.<a class="code" href="structPyZy_1_1Candidate.html#ace2643d0116bd20b0d82a22ff12ea139">text</a> &lt;&lt; std::endl;
        }
    }

    <span class="keywordtype">void</span> cursorChanged (<a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context) {
        std::cout &lt;&lt; <span class="stringliteral">&quot;cursor position is commited. [&quot;</span> &lt;&lt; context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#af44fc8c5c4a2102c9a19ba9dd3df753b" title="Returns a cursor position from the beginning of the input text.">cursor</a>()
                  &lt;&lt; <span class="stringliteral">&quot;]&quot;</span> &lt;&lt; std::endl;
    }
};

<span class="keywordtype">int</span> main() {
    <a class="code" href="classPyZy_1_1InputContext.html#a78cce1032342f094be615ec0dd3851cf" title="Initializes a InputContext class.">PyZy::InputContext::init</a>();

    <span class="comment">// create context with observer.</span>
    SampleObserver observer;
    <a class="code" href="classPyZy_1_1InputContext.html" title="Pinyin / Bopomofo conversion class.">PyZy::InputContext</a> *context = <a class="code" href="classPyZy_1_1InputContext.html#adf0f3aea2c16b5cf5838edec46444e27" title="Creates a new InputContext instance.">PyZy::InputContext::create</a>(
        <a class="code" href="classPyZy_1_1InputContext.html#aa34679a81ae706ccf452c6d6800b0391a02c67803c5a4c70704cd2be4bbdf9d62">PyZy::InputContext::FULL_PINYIN</a>, &amp;observer);

    <span class="comment">// set a property to enable simplified chinese mode.</span>
    <span class="comment">// This is a default value, so this is just a sample code.</span>
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a44e51396b86c6f266ee328b893146f51" title="Sets property of the context.">setProperty</a>(<a class="code" href="classPyZy_1_1InputContext.html#ad3f63e1ce4c49fe4e2fc11254bd4caaca12c8263f704b97e925bdd195be86ede7" title="Uses simplified chinese character. Default value is true.">PyZy::InputContext::PROPERTY_MODE_SIMP</a>,
                         <a class="code" href="classPyZy_1_1Variant.html#ae2da0df579118b9d93cf3a0b2adebc68" title="Creates a Variant object from the argument.">PyZy::Variant::fromBool</a> (<span class="keyword">true</span>));

    <span class="comment">// insert characters.</span>
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a0e1372a05cda00e57bb1ef49917ee025" title="Appends a new character on cursor position.">insert</a>(<span class="charliteral">&#39;n&#39;</span>);
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a0e1372a05cda00e57bb1ef49917ee025" title="Appends a new character on cursor position.">insert</a>(<span class="charliteral">&#39;i&#39;</span>);
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a0e1372a05cda00e57bb1ef49917ee025" title="Appends a new character on cursor position.">insert</a>(<span class="charliteral">&#39;h&#39;</span>);
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a0e1372a05cda00e57bb1ef49917ee025" title="Appends a new character on cursor position.">insert</a>(<span class="charliteral">&#39;a&#39;</span>);
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a0e1372a05cda00e57bb1ef49917ee025" title="Appends a new character on cursor position.">insert</a>(<span class="charliteral">&#39;o&#39;</span>);

    <span class="comment">// select a 5th candidate. (0 origin)</span>
    <span class="keywordflow">if</span> (context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a25a0c9ac7175ee2a713e990312e7f43b" title="Checks the candidate is exist or not.">hasCandidate</a>(4)) {
        context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a2a75b69c18b058a55827112f487e63ff" title="Selects a candidate and converts a rest text.">selectCandidate</a>(4);
    }

    <span class="comment">// commit text.</span>
    context-&gt;<a class="code" href="classPyZy_1_1InputContext.html#a93416c6aae249128df880905ff494b89" title="Fixes the conversion result.">commit</a>(<a class="code" href="classPyZy_1_1InputContext.html#afe8f3dd629c2b63fddc35bd7a856d8fda045eea76f069cf5fbf0a7798ad7d42e2">PyZy::InputContext::TYPE_CONVERTED</a>);

    <a class="code" href="classPyZy_1_1InputContext.html#ac197a8cd66bc0b85dd42339f5b283e08" title="Finalizes a InputContext class.">PyZy::InputContext::finalize</a>();

    <span class="keywordflow">return</span> 0;
}
</pre></div> </div></div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Wed Aug 1 2012 16:45:23 for pyzy by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.6.1
</small></address>

</body>
</html>
